
 /*********************************************************
 *
 *  Project:      Utilities
 *
 *  Class:        Helpers
 *
 *  File name:    Helpers.java
 *
 *
 *    SVN:
 *
 *    $Rev$:
 *    $Date$:
 *    $LastChangedBy$:
 *
 *    $HeadURL$:
 *
 **********************************************************/

package com.eastmountain.util;

import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics2D;
import java.awt.Point;


/*********************************************************
 *
 *  Class:   Helpers
 *
 **********************************************************/

public class Helpers {

    public static Point calculateFieldPosition( Graphics2D graphics2D, String text,
                                          int panelWidth, int panelHeight, Font font ) {

        Point point = new Point();
        int textWidth;
        int textHeight;
        int textAscent;

        FontMetrics metrics = graphics2D.getFontMetrics();
        textWidth = metrics.stringWidth( text );
        textHeight = metrics.getHeight();
        textAscent = metrics.getAscent();

        point.x = (panelWidth - textWidth) / 2;
        point.y = (panelHeight - textHeight) / 2 + textAscent;
/*
        System.out.println( "panelWidth: " + panelWidth + "   textWidth: " + textWidth
                                        + "\npanelHeight: " + panelHeight + "   textHeight: " + textHeight
                                        + "\npoint.x: " + point.x + "   point.y: " + point.y );
*/
        return point;

    }

}
